<?php
include('simple_html_dom.php');

function getDirListing() {
	$dirs = array();
	$d = dir(".");
	while (false !== ($entry = $d->read())) {
		if (is_dir("./".$entry) && $entry !== "." && $entry !== "..")
		array_push($dirs, $entry);
		//echo $entry."\n";
	}
	$d->close();
	return $dirs;
}
 
function scrapeURL($url, $id) {
    $id = (INT) $id;
    if ($id > 0) {
        return file_get_contents($url.'?id='.$id);
    }
    return "";
}

//"divctl00_cphCollegeNavBody_ucInstitutionMain_ctl00"
function parse_costs($html) {
    preg_match_all(
        '/<div id="divctl00_cphCollegeNavBody_ucInstitutionMain_ctl00".*?<table class="tabular">(.*?)<\/table>/s',
        $html,
        $fragments,
        PREG_SET_ORDER // formats data into an array
    );
    
    //foreach ($fragments as $frag) {
    //    print_r($frag);
    //}
    return $fragments[0][1];
}

//"divctl00_cphCollegeNavBody_ucInstitutionMain_ctl07"
function parse_accred($html_in) {
    $result = "";
    $html = str_get_html($html_in);
    // find all div tags with id=divctl00_cphCollegeNavBody_ucInstitutionMain_ctl07
    foreach($html->find('div#divctl00_cphCollegeNavBody_ucInstitutionMain_ctl07') as $e) {
        $result .= $e->innertext;
    }
    $html->clear(); 
	unset($html);
    return $result;
}

function scrapeURL_example($url, $id, $html_container_id) {
    $id = (INT) $id;
    if ($id > 0) {
        $html = file_get_contents($url.'?id='.$id);
        preg_match_all(
            '/<div id="'.$html_container_id.'".*?<table class="tabular">(.*?)<\/table>/s',
            $html,
            $fragments,
            PREG_SET_ORDER // formats data into an array
        );
        
        //foreach ($fragments as $frag) {
        //    print_r($frag);
        //}
        return $fragments[0][1];
    }
    return "";
}
 
?>
